package chunmap.example;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;

import chunmap.app.MapCtrl;
import chunmap.app.MapPanel;
import chunmap.app.tools.SelectTool;

public abstract class BaseAppletMap extends JApplet{
	private static final long serialVersionUID = -2489173152186500327L;

	protected MapCtrl map;
	protected SelectTool tool;
	
	@Override
	public void init(){
		super.init();
		
		this.setSize(850, 700);
		this.setLayout(new FlowLayout());
	
		//get map panel
		final MapPanel ui = initMap();
		this.add(ui);
		addButton(this,ui.getMap());
	}

	private MapPanel initMap() {
		MapPanel ui = new MapPanel(800, 510);
		ui.setPreferredSize(new Dimension(800, 510));
		map = ui.getMap();

		addLayer(map);

		map.fullView();
		map.refreshMap();
		return ui;
	}
	
	protected void addButton(Container frame,final MapCtrl map){
		UiUtil.addCommonButton(frame,map);
		
		UiUtil.addButton(frame,map,"选择",new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				tool=new SelectTool();
				map.setCurrentPlug(tool);
			}
		});
	}

	protected abstract void addLayer(MapCtrl map);
}
